package com.banmao.mall.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfigure implements WebMvcConfigurer {

    @Value("${myimage.fileSavePath}")
    private String fileSavePath;

    //@Override
    //public void addCorsMappings(CorsRegistry registry) {
    //    registry.addMapping("/**")
    //            .allowedOrigins("*")
    //            .allowedHeaders("*")
    //            .allowedMethods("*");
    //}

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置资源映射
        // 如果访问资源的路径是以“/static/images"开头，就去本机的文件夹下找
        registry.addResourceHandler("/static/images/**")
                .addResourceLocations("file:" + fileSavePath);
    }
}
